<!--********************************************************************
* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="GISdemo"></title>
    <script type="text/javascript" src="js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<input type="button" value="获取当前比例尺" onclick="getinfo()" style="position:absolute;z-index:99999"/>
<input type="button" value="获得索引" onclick="getindex()" style="position:absolute;z-index:99999;left:150px"/>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" exclude="iclient-classic" src="dist/classic/include-classic.js"></script>
<script type="text/javascript">
    var map, layer,url = "http://127.0.0.1:8090/iserver/services/map-ugcv5-World/rest/maps/World";
	var scales = [1/295829355.454566,1/147914677.727283,1/73957338.8636414,1/36978669.4318207,1/18489334.7159104];
	var vectorLayer,point,pointVector;
	//var scales = [1/295829355.454566];
    //初始化地图
    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.Navigation()]
    });
	vectorLayer = new SuperMap.Layer.Vector();
    map.addControl(new SuperMap.Control.MousePosition());
    //初始化图层
    layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {transparent: true, cacheEnabled:true}, {maxResolution: "auto",scales:scales});
    //监听图层信息加载完成事件
    layer.events.on({"layerInitialized": addLayer});
    function addLayer() {
        map.addLayers([layer,vectorLayer]);
        //显示地图范围
        map.setCenter(new SuperMap.LonLat(0,0), 0);
		point = new SuperMap.Geometry.Point(-120,32);
		pointVector = new SuperMap.Feature.Vector(point);
		//添加矢量图形覆盖物
		vectorLayer.addFeatures(pointVector);
    }

	function getinfo(){
		alert("scale:  1:" + (1/map.getScale()) + ";resolution:   " + map.getResolution());
	}

	function getindex(){
		var dpi = 96;
		var left = -180;
		var top = 90;
		var tileWidth = 256;
		var x = -120;
		var y = 32;
		var tileRectangle = 256;

		var oneTileDis = map.getResolution() * tileWidth;
		var xMinus = Math.abs(left - x);
		var yMinus = top - y;
		
		 
		var yPos = Math.floor(xMinus/oneTileDis);
		var xPos = Math.floor(yMinus/oneTileDis);

		var yIndex = Math.floor((yPos + 1)/tileRectangle);
		var xIndex = Math.floor((xPos + 1)/tileRectangle);

		var fileName = Math.round(1/map.getScale());

		alert("http://127.0.0.1:8080/World/P8_256_DCF34B56FIX/" + fileName + "/" + yIndex + "/" + xIndex + "/" + yPos + "x" + xPos + "." + "png");
	}
</script>
</body>
</html>